using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Configuration;
using System.Web.Configuration;

namespace Framework.Library.Helper
{
    public class ConfigHelper
    {
        public static bool GetBoolSetting(string key, bool defaultValue)
        {
            if (StringHelper.IsCaseInsensitiveMatch(GetSetting(key), "true")) return true;
            if (StringHelper.IsCaseInsensitiveMatch(GetSetting(key), "false")) return false;
            return defaultValue;
        }

        public static int GetIntSetting(string key, int defaultValue)
        {
            int setting;
            return int.TryParse(GetSetting(key), out setting) ? setting : defaultValue;
        }

        public static string GetStringSetting(string key, string defaultValue)
        {
            return (GetSetting(key) ?? defaultValue);
        }	

        public static string GetSetting(string key)
        {
            return WebConfigurationManager.AppSettings[key];
        }
    }
}
